-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expose MCP server instructions in MCPServer.instructions property
#3431
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
docs/mcp/client.md
Outdated
| async def main(): | ||
| async with agent: | ||
| # Access server instructions after connection is established | ||
| if server.instructions: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's update the example to show those these instructions would be used in the agent instructions, using a dynamic instructions function:
@agent.instructions
async def mcp_server_instructions():
return server.instructionsWhen that's called, I believe the server connection is guaranteed to have been established.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the example.
83315d8 to
2238e39
Compare
tests/test_mcp.py
Outdated
| mcp_server.instructions | ||
| async with mcp_server: | ||
| # The test server doesn't provide instructions, so it should be None | ||
| assert mcp_server.instructions is None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we give the test server some instructions so we can verify it actually works? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated - added instructions on the mcp_server.py's test server.
docs/mcp/client.md
Outdated
|
|
||
| @agent.instructions | ||
| async def mcp_server_instructions(): | ||
| return server.instructions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add a tooltip here to make it clear that the connection is guaranteed to be established by this point.
You can add a tooltip by adding a # (1)! comment, and then a numbered list below the code snippet. You can find some examples elsewhere in the docs, and verify it works by running make docs-serve
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated and tested too, let me know if it works.
0b5cfcf to
3916338
Compare
MCPServer.instructions property
Implements #3353